/****Accenture IDC
Author - Sapna Jaamdar  v1.0
Revisions:
Bibhu Mishra
Bhumika Udani      v2.0             dt:14 March 2012        Updated the Query as per req # 1170 
*/

global class scheduledSharkpool implements Schedulable{
    public ID OORSaltLakeCityQueueId ;    
    public static ID LocalAdsLeadRecordType = RecordTypeHelper.GetRecordTypeID('Lead', 'Local Advertiser');
    
    Map<string,id> QueryMap = new Map<string,id>();
    List<QueueSobject> OORQuerylist = [Select QueueId,queue.name from QueueSobject q where sobjecttype ='Lead'];
    Set<Id> queueId= New Set<Id>();
        
        global void execute(SchedulableContext sc) {
        for(QueueSobject QS:OORQuerylist){
        QueryMap.put(QS.queue.name,QS.QueueId);  
        queueId.add(QS.QueueId);
        }
        SharkpoolOwnerReassignment reassign = new SharkpoolOwnerReassignment();
        reassign.QueueSet = queueId;
        //reassign.query='SELECT Id, Name,phone, company,status, LeadSource,createddate,Last_Worked__C, Ownerid,Owner.Email FROM Lead WHERE Lead_Status_ReadOnly__c !=\'' + 'Closed' + '\' and Lead_Status_ReadOnly__c !=\'' + 'Invalid Lead' + '\' and (LeadSource=\'' + 'Internet' + '\' or LeadSource =\'' + 'Call In' + '\' or LeadSource =\'' + 'Email-In' + '\' ) and LeadSource!= null and isConverted = false and (ownerid !=\'' + OORSaltLakeCityQueue.QueueId  + '\'' + ' and ownerid !=\'' + OORNewJerseyQueue.QueueId + '\''+ ') and recordtypeid =\'' + LocalAdsLeadRecordType + '\'';
        reassign.query='SELECT Id, User_Office_Code__c,User_Office_Code__c,Date_Assigned__c,Name,Days_Untouched__c,phone, company,status, LeadSource,createddate,Last_Worked__C,Date_Assigned__c, Ownerid,Owner.Email FROM Lead WHERE LeadSource=\'' + 'Internet' + '\' and isConverted = false  AND OwnerId NOT IN: QueueSet AND Owner.UserRoleId != NULL AND recordtypeid =\'' + LocalAdsLeadRecordType + '\'';
        reassign.email='salesforce@attinteractive.com';
        reassign.toSaltLakeQueueId= QueryMap.get('Sharkpool - Salt Lake (SLC)');
        reassign.toNewJerseyQueueId= QueryMap.get('Sharkpool - New Jersey (NNJ)');
        reassign.toAllentownQueueId= QueryMap.get('Sharkpool - Allentown (NEP)');
        reassign.toBaltimoreQueueId= QueryMap.get('Sharkpool - Baltimore (BLT)');
        reassign.toBostonQueueId= QueryMap.get('Sharkpool - Boston (BOS)');
        reassign.toDenverQueueId= QueryMap.get('Sharkpool - Denver (DEN)');
        reassign.toHarrisburgQueueId= QueryMap.get('Sharkpool - Harrisburg (HPA)');
        reassign.toLasVegasQueueId= QueryMap.get('Sharkpool - Las Vegas (LVN)');
        reassign.toLongIslandQueueId= QueryMap.get('Sharkpool - Long Island (LIN)');
        reassign.toMinneapolisQueueId= QueryMap.get('Sharkpool - Minneapolis (MIN)');
        reassign.toNewYorkQueueId= QueryMap.get('Sharkpool - New York (NYC)');
        reassign.toOaktonQueueId= QueryMap.get('Sharkpool - Oakton (NVA)');
        reassign.toPhiladelphiaQueueId= QueryMap.get('Sharkpool - Philadelphia (PHI)');
        reassign.toPhoenixQueueId= QueryMap.get('Sharkpool - Phoenix (PHX)');
        reassign.toPittsburghQueueId= QueryMap.get('Sharkpool - Pittsburgh (PIT)');
        reassign.toPortlandQueueId= QueryMap.get('Sharkpool - Portland (POR)');
        reassign.toProvidenceQueueId= QueryMap.get('Sharkpool - Providence (PRI)');
        reassign.toRichmondQueueId= QueryMap.get('Sharkpool - Richmond (RVA)');
        reassign.toSeattleQueueId= QueryMap.get('Sharkpool - Seattle (SWA)');
        reassign.toVirginiaQueueId= QueryMap.get('Sharkpool - Virginia Beach (VVA)');
        reassign.toWhitePlainsQueueId= QueryMap.get('Sharkpool - White Plains (WPN)');
        reassign.toGeneralQueueId= QueryMap.get('SFA OOR General Sharkpool Queue');
        reassign.toHendersonQueueId = QueryMap.get('Sharkpool - Henderson(HEN)');
        reassign.toCharlotteQueueId = QueryMap.get('Sharkpool - Charlotte (CHA)');
        
        ID batchprocessid = Database.executeBatch(reassign,10);
    }
          
/* test class for classes/triggers */
 
  static testMethod void testScheduledSharkpool() {
        test.starttest();
        scheduledSharkpool pool = new scheduledSharkpool();
        String sch = '0 0 23 * * ?';
        system.schedule('Scheduled Sharkpool', sch, pool);
        test.stopTest();
  }          
}